package game.poker.holdem.entity;

import game.poker.holdem.card.Card;
import game.poker.holdem.card.CommunityCards;
import game.poker.holdem.card.Deck;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Dealer {
    private String name;
    private Deck deck;
    
    private Table table;
    
    public Dealer(String name) {
        this.name = name;
        deck = new Deck();
    } 
        
    public String getName() {
        return name;
    }
    
    public void distribute() {
        deck.shuffle();
        List<Player> players = table.getPlayers();
        for(Player player : players) {
            player.takeCard(deck.nextCard());
            player.takeCard(deck.nextCard());
        }
    }
    
    public void flop() {
        List<Card> flopCards = new ArrayList<Card>();
        flopCards.add(deck.nextCard());
        flopCards.add(deck.nextCard());
        flopCards.add(deck.nextCard());
        table.getCommunityCards().setFlopCards(flopCards);
    }
    
    public void turn() {
        Card turnCard = deck.nextCard();
        table.getCommunityCards().setTurnCard(turnCard);
    }
    
    public void river() {
        Card riverCard = deck.nextCard();
        table.getCommunityCards().setRiverCard(riverCard);
    }
    
    public void gatherCards() {
        List<Player> players = table.getPlayers();
        for(Player player : players) {
            Set<Card> cards = player.returnCards();
            deck.addCards(cards);
        }
        CommunityCards communityCards = table.getCommunityCards();
        deck.addCards(communityCards.getAllCards());
    }
    
    public void shuffleDeck() {
        deck.shuffle();
    }

    public void setTable(Table table) {
        this.table = table;
    }
    
    
}
